﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;


namespace Cards
{
    class Board
    {
        #region Variables

        //textures for the player chips
        Texture2D p1Chip, p2Chip;

        public enum chipState
        {
            empty, //nothing on board
            p1, //player 1 chip on board
            p2 //player 2 chip on board
        };

        public static chipState[] chips;

        #endregion

        public Board()
        {
            chips = new chipState[101];
        }

        public void LoadContent(ContentManager Content)
        {
            p1Chip = Content.Load<Texture2D>("player1Chip");
            p2Chip = Content.Load<Texture2D>("player2Chip");
        }

        public void Draw(SpriteBatch spriteBatch, Input playerInput)
        {            
            spriteBatch.Begin();

            int y = 0;
            int x = 0;


            //loop through all spots on the board drawing the appropriate pieces
            for (int loc = 1; loc <= 100; loc++)
            {
                //find the right y component with a given position
                if (loc >= 1 && loc <= 10)
                    y = 1;
                if (loc >= 11 && loc <= 20)
                    y = 2;
                if (loc >= 21 && loc <= 30)
                    y = 3;
                if (loc >= 31 && loc <= 40)
                    y = 4;
                if (loc >= 41 && loc <= 50)
                    y = 5;
                if (loc >= 51 && loc <= 60)
                    y = 6;
                if (loc >= 61 && loc <= 70)
                    y = 7;
                if (loc >= 71 && loc <= 80)
                    y = 8;
                if (loc >= 81 && loc <= 90)
                    y = 9;
                if (loc >= 91 && loc <= 101)
                    y = 10;

                //find the correct x location given the position
                if ((loc % 10) == 0)//far right case
                    x = 10;
                else
                    x = loc % 10;

                //draw pieces
                if (chips[loc] == chipState.p1)
                {
                    spriteBatch.Draw(p1Chip, new Vector2((x * 65) + 12, (y * 40) + 8), new Rectangle(0, 0, p1Chip.Width, p1Chip.Height), Color.White, 0, new Vector2(0, 0), .5f, 0, 0);
                }
                else
                {
                    if (chips[loc] == chipState.p2)
                    {
                        spriteBatch.Draw(p2Chip, new Vector2((x * 65) + 12, (y * 40) + 8), new Rectangle(0, 0, p1Chip.Width, p1Chip.Height), Color.White, 0, new Vector2(0, 0), .5f, 0, 0);
                    }
                }
            }

#region foreach stuff    
            /*
            foreach(chipState chip in chips)
            {
                if (chip == chipState.p1)
                {
                    //this.EndDraw();
                    spriteBatch.Draw(p1Chip, new Vector2(playerInput.cursorPosition[playerInput.position].X, playerInput.cursorPosition[playerInput.position].Y), new Rectangle(0, 0, p1Chip.Width, p1Chip.Height), Color.White, 0, new Vector2(0, 0), .5f, 0, 0);
                }
                if (chip == chipState.p2)
                {
                    spriteBatch.Draw(p2Chip, new Vector2(playerInput.cursorPosition[playerInput.position].X, playerInput.cursorPosition[playerInput.position].Y), new Rectangle(0, 0, p1Chip.Width, p1Chip.Height), Color.White, 0, new Vector2(0, 0), .5f, 0, 0);
                }
            }
            */
#endregion

            spriteBatch.End();
        }
    }
}
